import Vue from 'vue'
import App from './App.vue'
import router from './router'
/* 导入阿里图标 */
import './assets/fonts/iconfont.css'
/* 导入全局css */
import './assets/css/global.scss'

/* TreeTable 表格插件 */
import TreeTable from 'vue-table-with-tree-grid'
Vue.component('tree-table', TreeTable) // 注册插件 Vue.component(TreeTable.name, TreeTable)

/* 富文本编译器 */
import VueQuillEditor from 'vue-quill-editor'
Vue.use(VueQuillEditor)

/* 时间过滤器 */
Vue.filter('dateFormat', function (data) {
  const dt = new Date(data)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

/* 浏览器进度条 */
import NProgress from 'nprogress'

/* 设置 axios */
import axios from 'axios'
/* 配置请求的根路径 */
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
Vue.prototype.$axios = axios

/* 请求 */
axios.interceptors.request.use(config => {
  /* 设置请求头 */
  var token = window.sessionStorage.getItem('token')
  if (token) {
    config.headers.Authorization = token
  }
  NProgress.start()
  return config
})

/* 响应 */
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
})

/* 阻止启动生产消息，常用作指令 */
Vue.config.productionTip = false

/* 创建vue实例 */ 
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')